<template>
  <div>
    <BaseTable ck op :columns="columns"  :data="data" @update="udpate"></BaseTable>
       <Modal
        v-model="udpateFlag"
        :title="formItem.DeptName"
        @on-ok="updateHandler"
        @on-cancel="cancelHandler">
        <Form ref="formInline" :model="formItem" >
            <FormItem label="推荐创新训练数">
                <InputNumber   v-model="formItem.Params1">
                    <Icon type="ios-person-outline" slot="prepend"></Icon>
                </InputNumber >
            </FormItem>
            <FormItem label="推荐创业训练数">
                <InputNumber   v-model="formItem.Params2" >
                    <Icon type="ios-lock-outline" slot="prepend"></Icon>
                </InputNumber >
            </FormItem>
            <FormItem label="推荐创业实践数">
                <InputNumber   v-model="formItem.Params3">
                    <Icon type="ios-lock-outline" slot="prepend"></Icon>
                </InputNumber>
            </FormItem>
        </Form>
    </Modal>
  </div>
</template>

<script>
import BaseTable from '@c/table/table.vue';
export default {
  name: 'DeptParams',
  data () {
    return {
      columns: [
        {
          title: ' ',
          type: 'index'
        },
        {
          title: '部门',
          key: 'DeptName'
        },
        {
          title: '推荐创新训练数',
          key: 'Params1'
        },
        {
          title: '推荐创业训练数',
          key: 'Params2'
        },
        {
          title: '推荐创业实践数',
          key: 'Params3'
        }
      ],
      data: [],
      formItem: {},
      udpateFlag: false
    };
  },
  components: {
    BaseTable
  },
  methods: {
    getAll () {
      this.$api.GetAllDeptProject().then((res) => {
        console.log(res.Data);
        this.data = res.Data;
      }).catch((err) => {
        if (err) {
          this.$Message.error(err);
        }
      });
    },
    udpate (rows) {
      console.log(rows);
      if (Array.isArray(rows) && rows.length === 1) {
        this.formItem = rows[0];
        this.udpateFlag = true;
      } else {
        this.$Message.warning('请选择一条数据操作！');
      }
    },
    updateHandler () {
      console.log(this.formItem);
      this.$api.UpdateDeptProject(this.formItem).then((res) => {
        this.$Message.success('修改成功！');
        this.getAll();
      }).catch((err) => {
        if (err) {
          this.$Message.error(err);
          this.getAll();
        }
      });
    },
    cancelHandler () {
      this.formItem = {};
    }
  },
  mounted () {
    this.getAll();
  }
};
</script>

<style scoped>

</style>